package com.dongdongshop.Controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbSpecification;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.service.SpecificationService;
import com.dongdongshop.service.TempLateService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tempLateController")
public class TempLateController {

    @Reference
    private TempLateService tempLateService;
    @Reference
    private BrandService brandService;
    @Reference
    private SpecificationService specificationService;

    @RequestMapping("toTempLate")
    public String toTempLate(Model model){
        //品牌
        List<TbBrand> brandList = brandService.findAll();
        //规格
        List<TbSpecification> specList = specificationService.selectAll();

        model.addAttribute("brandList",brandList);
        model.addAttribute("specList",specList);
        return "admin/type_template";
    }

    @RequestMapping("findTempLateAll")
    @ResponseBody
    public Result findAll(String name){
        List<TbTypeTemplate> tempList =  tempLateService.findAll(name);
        return Result.build(ConstantEnum.SUCCESS).setResult(tempList);
    }

    @RequestMapping("addInfo")
    @ResponseBody
    public Result addInfo(TbTypeTemplate tbTypeTemplate){
        boolean b = tempLateService.insert(tbTypeTemplate);
        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("update/{id}")
    @ResponseBody
    public Result update(@PathVariable("id") Long id,Model model){

        List<TbTypeTemplate> typeList =  tempLateService.selectById(id);

        return Result.build(ConstantEnum.SUCCESS).setResult(typeList);
    }

    @RequestMapping("update1")
    @ResponseBody
    public Result update1(TbTypeTemplate tbTypeTemplate){

        boolean b = tempLateService.updateInfo(tbTypeTemplate);

        return Result.build(ConstantEnum.SUCCESS);
    }
    @RequestMapping("deleteAll")
    @ResponseBody
    public Result deleteAll(Integer[] arr){
        boolean b = tempLateService.deleteAll(arr);
        return Result.build(ConstantEnum.SUCCESS);
    }
}
